﻿@model Kooboo.CMS.Sites.Models.Page
@{
    var cacheInMemory = Model.OutputCache != null && Model.OutputCache.EnableCaching != null && Model.OutputCache.EnableCaching.Value == true;
}
<table>
    <tr>
        <th></th>
        <td>
            <input type="radio" name="cacheType" value="0" id="radio_NoCache" @((Model.CacheToDisk == false && !cacheInMemory) ? "checked" : "") /><label for="radio_NoCache" class="inline">@("No cache".Localize())</label></td>
    </tr>
    <tr>
        <th></th>
        <td>
            <input type="radio" name="cacheType" value="1" id="radio_CacheToDisk" @((Model.CacheToDisk) ? "checked" : "")/><label for="radio_CacheToDisk" class="inline">@("Cache to disk".Localize())</label>
            @Html.HiddenFor(m => m.CacheToDisk)
        </td>
    </tr>
    <tr>
        <th></th>
        <td>
            <input type="radio" name="cacheType" value="2" id="radio_CacheInMemory" @(cacheInMemory ? "checked" : "")/><label for="radio_CacheInMemory" class="inline">@("Cache in memory".Localize())</label>
            @Html.HiddenFor(m => m.OutputCache.EnableCaching)
        </td>
    </tr>
    @Html.EditorFor(m => m.OutputCache.Duration, new { HtmlAttributes = new { @class = "medium" } })
    @Html.EditorFor(m => m.OutputCache.ExpirationPolicy, new { HtmlAttributes = new { @class = "medium" } })
</table>
<script>
    $(function () {
        var $cacheInMemory = $('#radio_CacheInMemory');
        var $memorySetting = $cacheInMemory.parent().parent().nextAll();
               
        $('[name=cacheType]').change(function () {
            var $self = $(this);            
            switch ($self.val()) {
                case '0':
                    $memorySetting.hide();
                
                    $('#CacheToDisk').val('False');
                    $('#OutputCache_EnableCaching').val('False');
                    break;
                case '1':
                    $memorySetting.show();                   
                    $('#CacheToDisk').val('True');
                    $('#OutputCache_EnableCaching').val('False');
                    break;
                case '2':
                    $memorySetting.show();                  

                    $('#CacheToDisk').val('False');
                    $('#OutputCache_EnableCaching').val('True');
                    break;

            }
        });
        $('[name=cacheType]:checked').trigger('change');
    });
</script>
